package com.hulk.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hulk.dao.HelloWorldMapper;
import com.hulk.model.HelloWorld;
import com.hulk.redis.core.CommonCacheService;
import com.hulk.redis.core.RedisHelper;
import com.hulk.service.HelloWorldService;
import com.hulk.utils.CalloutServices;

/**
 * {�ô�˵���ù��캯���ĺ��弰����}
 * 
 * @author Liuxingwen
 * @created 2016��9��3�� ����1:43:46
 * @lastModified
 * @history �����ڸ����ӿ����ϣ���ctrl+1�� alt+shift+s ѡ��override/Implement
 *          methods...ѡ��������Ҫʵ�ֵķ���
 */
@Service("helloWorldService")
public class HelloWorldServiceImpl implements HelloWorldService {
	
	@Resource
	HelloWorldMapper helloWorldMapper;
	
	@Resource
	CommonCacheService commonCacheService;
	
	@Resource
	RedisHelper redisHelper;

	/**
	 * @param model
	 * @return
	 * @throws Exception
	 * @author Liuxingwen
	 * @created 2016��9��3�� ����1:46:55
	 * @lastModified
	 * @history
	 */
	public int addNew(HelloWorld model) throws Exception {
		// TODO Auto-generated method stub
		return helloWorldMapper.addNew(model);
		// return 100;
	}

	/**
	 *  @param id
	 *  @return
	 *  @throws Exception
	 *  @author Liuxingwen
	 *  @created 2016年9月20日 上午10:32:33
	 *  @lastModified      
	 *  @history            
	 */
	@Override
	public HelloWorld selectOne(int id) throws Exception {
		// TODO Auto-generated method stub
		return helloWorldMapper.selectOne(id);
	}

	/**
	 *  @param model
	 *  @return
	 *  @throws Exception
	 *  @author Liuxingwen
	 *  @created 2016年9月20日 上午11:45:54
	 *  @lastModified      
	 *  @history            
	 */
	@Override
	public int update(HelloWorld model) throws Exception {
		// TODO Auto-generated method stub
		return helloWorldMapper.update(model);
	}

	/**
	 *  @param name
	 *  @return
	 *  @author Liuxingwen
	 *  @created 2016年9月22日 上午10:17:55
	 *  @lastModified      
	 *  @history            
	 */
	@Override
	public String hello(String name) {
		// TODO Auto-generated method stub
		return "RUN SUCCESS:" + name;
	}

	@Override
	public Object testRedis() {
		redisHelper.set("abc", "abc");
		Object v = commonCacheService.setObject("abc", "abc", "def");
		return v;
	}

	public List<Map<String,Object>> selectAll() throws Exception{
		Date date1 = new Date();
		List<Map<String,Object>> lst = helloWorldMapper.selectAll();
		Date date2 = new Date();
		System.out.println("耗时===="+(date2.getTime()-date1.getTime()));
		return lst;
	}
	
	@Override
	public void testAsyncMethod() throws InterruptedException{
		Map<String, Object> paras = new HashMap<String, Object>();
		AsyncMethod push = new AsyncMethod(paras);
		CalloutServices.executor(push);
		System.out.println(11);
	}
	
	
	/**
	 * 异步更新调用方法
	 * @author Administrator
	 *
	 */
	class AsyncMethod implements Runnable {
		 private Map<String, Object> paras ;
		 
		public AsyncMethod(Map<String, Object> paras){
//				this.pushDao = pushDao;
				this.paras = paras;
		}
		
		@Override
		public void run() {
			try {
				System.out.println("这里是异步调用.............");
			} catch (Exception e) {
//				logger.error(e.getMessage());
				e.printStackTrace();
			}
		}
	}
}
